package com.haistand.module.common.velocity;


import com.haistand.module.common.core.ApplicationConstants;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @author :anjero
 * @version :1.0
 * @Title :VelocityUtils.java
 * @Description:
 * @Datetime : 2014-5-30 下午5:29
 * @Copyright :Copyright (c) 2012
 * @Company :Cheshell
 */

public class VelocityUtils {

    public static String url() throws UnsupportedEncodingException {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

        String url = request.getScheme() + "://" + request.getServerName()
                + ":" + request.getServerPort() ;
        url = url + request.getRequestURI();
        if (url.indexOf("/login") > 0) {
            url = url.replace("/login", "/");
        }
        return URLEncoder.encode(url, "UTF-8");
    }


    public static String staticUrl(String path) {
        return ApplicationConstants.staticUrl() + path;
    }
    public static String staticUrl() {
        return ApplicationConstants.staticUrl();
    }
}
